// pages/posts/post-detail/post-detail.js
var postDataSet = require("../../../data/posts-data.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.data.id = id;
    var postData = postDataSet.postList[id];
    var postsCollected = wx.getStorageSync('postsCollected');
    if (postsCollected) {
      var postCollected = postsCollected[id];
      if (postCollected) {
        this.setData({
          collected: postCollected
        })
      }
    }
    else {
      var postCollected = {};
      postCollected[id] = false;
      wx.setStorageSync('postsCollected', postCollected)
    }

    this.setData({
      postData: postData
    })

    wx.setStorageSync('key', {
      storage: "Storage测试用例",
      name: "这是storage中的name"
    })

    // console.log(postData);
    // id=1;
  },
  /**
    * 收藏按钮。用的linux企鹅。
    */
  onCollectionTap: function (event) {

    var postsCollected = wx.getStorageSync('postsCollected');
    var postCollected = postsCollected[this.data.id];
    postCollected = !postCollected;
    postsCollected[this.data.id] = postCollected;
    wx.setStorageSync('postsCollected', postsCollected);
    this.setData({
      collected: postCollected
    })
    wx.showToast({
      title: postCollected ? "收藏成功" : "取消收藏成功",
      icon: "success",
    })
    

    // wx.setStorageSync('key', {
    //   storage: "Storage测试用例",
    //   name: "这是storage中的name"
    // })
    // var storage = wx.getStorageSync('key')
    // console.log(storage)

  },

  /**
   * 分享按钮。用的三角形
   */
  onShareTap: function (event) {

    var itemList = [
        "分享给朋友",
        "分享到朋友圈",
        "点错了，不想分享"
      ];
    wx.showActionSheet({
      alertText:"警告！点了以后手机将会爆炸",
      itemList:itemList,
      itemColor:"blue",
      success:function(res){
        var idx = res.tapIndex;
        wx.showModal({
          title:"将要" + itemList[idx],
          cancelColor: 'cancelColor',
          content:"这里是内容"
        })
      }
    })
  },
  onMusicTap:function(event){
    this.mapCtx = wx.createMapContext('myMap')
    const innerAudioContext = wx.crinnerAudioContext.autoplay = true
    innerAudioContext.src = 'http://www.htqyy.com/play/23';
    wx.showToast({
      title: '开始播放',
    })
  },
  /**
   * 
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }




})